<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="common/css_js.jsp"></jsp:include>
<%
    String path = request.getContextPath();
%>
<html>
<head>
    <title>订单信息</title>
</head>
<%-- 导入窗口插件 --%>
<script src="<%=path%>/static/jquery/jquery-3.6.0.min.js"></script>
<script src="<%=path%>/static/hui/lib/layer/2.4/layer.js"></script>
<script src="<%=path%>/static/js/common.js"></script>
<body>
<div class="container">
    <div class="mt-5">
        <table class="table">
            <thead>
            <tr>
                <td>ID</td>
                <td>顾客id</td>
                <td>员工id</td>
                <td>订单配送方式</td>
                <td>订单产生时间</td>
                <td>座位id</td>
                <td>订单状态</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageData.list}" var="one">
                <tr>
                    <td>${one.o_Id}</td>
                    <td>${one.c_Id}</td>
                    <td>${one.e_Id}</td>
                    <td>
                        <c:if test="${one.o_Method == 0}">在店就餐</c:if>
                        <c:if test="${one.o_Method == 1}">外卖</c:if>
                    </td>
                    <td>${one.order_Time}</td>
                    <td>
                        <c:if test="${one.o_Method == 0}">${one.s_Id}</c:if>
                        <c:if test="${one.o_Method == 1}">0</c:if>
                    </td>
                    <td>
                        <c:if test="${one.o_State == 0}">已接收订单</c:if>
                        <c:if test="${one.o_State == 1}">正在做菜</c:if>
                        <c:if test="${one.o_State == 2}">正在配送</c:if>
                        <c:if test="${one.o_State == 3}">配送完成</c:if>
                    </td>
                    <td>
                        <button type="button" class="btn btn-info"
                                onclick="layer_show('修改订单信息','update?o_id=${one.o_Id}',600,400)">修改
                        </button>
                        <button type="button" class="btn btn-danger" onclick="deleteOrder(${one.o_Id})">取消订单</button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
    <div class="container">
        <div class="col-md-6 offset-md-3">
            <div class="center-align">
                <div id="page">
                    <button class="btn btn-secondary" onclick="firstPage()">首页</button>
                    <button class="btn btn-secondary" onclick="prevPage()">上一页</button>
                    <button class="btn btn-secondary" onclick="nextPage()">下一页</button>
                    <button class="btn btn-secondary" onclick="lastPage()">尾页</button>
                    <span>当前第${pageData.currentPage}页，共${pageData.totalPage}页，共${pageData.totalSize}条记录</span>
                </div>
            </div>
        </div>
    </div>
    <div class="container mt-5">
        <div class="col-md-6 offset-md-3">
            <div class="center-align">
                <div class="h3">
                    <p class="text-muted">订单总成本：${orderTotal}</p>
                </div>
                <div class="h3">
                    <p class="text-success">订单总收入：${allMoney}</p>
                </div>
                <div class="h1">
                    <p class="text-danger">收益：${getMoney}</p>
                </div>
            </div>
        </div>
    </div>
    <script>
        var pageSize = ${pageData.pageSize};
        var pageNumber = ${pageData.currentPage};
        var totalPage = ${pageData.totalPage};

        function firstPage() {
            if (pageNumber != 1) {
                pageNumber = 1;
                gotoPage();
            }
        }

        function prevPage() {
            if (pageNumber > 1) {
                pageNumber--;
                gotoPage();
            }
        }

        function nextPage() {
            if (pageNumber < totalPage) {
                pageNumber++;
                gotoPage();
            }
        }

        function lastPage() {
            if (pageNumber != totalPage) {
                pageNumber = totalPage;
                gotoPage();
            }
        }

        function gotoPage() {
            window.location.href = "${pageContext.request.contextPath}/employeeOrder/queryAllOrder?pageSize=" + pageSize + "&pageNumber=" + pageNumber;
        }
    </script>
    <script>
        function deleteOrder(o_id) {
            if (confirm("你确定要删除该订单信息吗?")) {
                $.ajax({
                    url: "deleteOrder",
                    method: "post",
                    dataType: "text",
                    /*contentType:"application/x-www.-form-urlencoded",*/
                    data: {
                        o_id: o_id
                    },
                    success: function (result) {
                        if (result == "success") {
                            window.location.href = "queryAllOrder";
                            alert("取消订单成功");
                        } else {
                            alert("取消订单成功");
                        }
                    }, error: function (e) {
                        alert("服务器错误");
                    }
                })
            }
        }
    </script>
</div>
</body>
</html>
